package main

import "fmt"

func main() {
	matrix := [][]int{
		{1, 4, 7, 11, 15},
		{2, 5, 8, 12, 19},
		{3, 6, 9, 16, 22},
	}
	target := 5
	fmt.Println(searchMatrix(matrix, target))
}

func searchMatrix(matrix [][]int, target int) bool {
	//首先根据target判断行
	columnMax, rowMax := len(matrix), len(matrix[0])
	for column := 0; column < columnMax; column++ {
		for row := 0; row < rowMax; row++ {
			if matrix[column][row] > target {
				rowMax = row
			}
			if matrix[column][row] == target {
				return true
			}
		}
	}
	return false

}
